// pages/news_detail/news_detail.js
const request = require('../../utils/promise.js');
const WxParse = require('../../wxParse/wxParse.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    newsId: null,
    htmlStr: '',
    newsInfo: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      newsId: options.newsId
    })
    this.reqNewsDetailInfo();
  },

  /**
   * 页面被用户分享时执行
   */
  onShareAppMessage() {
    return {
      title: '动态详情'
    }
  },

  /**
   * 根据 id 获取动态详情信息
   */
  reqNewsDetailInfo() {
    request.GET('/news/newsInfo', {id: this.data.newsId}).then(res => {
      // console.log(res)
      if (res.data.resCode==200 && res.data.newsInfo) {
        this.setData({
          newsInfo: res.data.newsInfo,
          htmlStr: res.data.newsInfo['content']? res.data.newsInfo['content']: '',
        })
        var that = this;
        WxParse.wxParse('article', 'html', this.data.htmlStr, that, 5);
      } else {
        wx.showToast({
          title: '获取数据异常',
          icon: 'error'
        })
      }
    })
  },

})